package com.example.demo.Service.Impl;

import com.example.demo.Dao.OrderMapper;
import com.example.demo.Entity.Order;
import com.example.demo.Param.OrderInsertParam;
import com.example.demo.Param.OrderUpdateParam;
import com.example.demo.Service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class OrderServiceImpl implements OrderService {

    @Autowired
    private OrderMapper orderMapper;

    @Override
    public List<Order> getAll() {
        List<Order> orders = orderMapper.selectAll();
        return orders;
    }

    @Override
    public void deleteOrder(Long id) {
        orderMapper.deleteByPrimaryKey(id);
    }

    @Override
    public void updateOrder(Long id) {

    }

    @Override
    public Order createOne(OrderInsertParam orderInsertParam) {
        Order order = new Order();
        order.setProductname(orderInsertParam.getProductname());
        order.setCustomerId(orderInsertParam.getCustomerId());
        order.setQuantity(orderInsertParam.getQuantity());
        order.setSku(orderInsertParam.getSku());
        order.setSpu(orderInsertParam.getSpu());
        orderMapper.insert(order);
        return order;
    }

    @Override
    public void updateOrder(OrderUpdateParam orderUpdateParam) {
        Order order = new Order();
        order.setId(orderUpdateParam.getId());
        order.setProductname(orderUpdateParam.getProductname());
        order.setCustomerId(orderUpdateParam.getCustomerId());
        order.setQuantity(orderUpdateParam.getQuantity());
        order.setSku(orderUpdateParam.getSku());
        order.setSpu(orderUpdateParam.getSpu());
        orderMapper.updateByPrimaryKey(order);
    }

    @Override
    public List<Order> searchOrder(Long customerId) {
        return orderMapper.selectByCustomerId(customerId);
    }

}
